/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-16
 * Time: 22:27
 */
class Solution4 {
    int left = 0;
    public int wiggleMaxLength(int[] nums) {
        int n = nums.length;
        if(n < 2) {
            return n;
        }

        int ret = 0,left = 0;
        for(int i = 0; i < n-1; i++) {
            int right = nums[i+1]-nums[i];
            if(right == 0) {
                continue;
            }
            if(left * right <= 0) {
                ret++;
            }
            left = right;
        }
        return ret+1;
    }
}
